export function getToDate (from , end) {
    const dis = end.getTime() - from.getTime();
    if (dis <= 1000 * 60 * 60 * 24 * 3) {
        return 'hour';
    }
    if (dis <= 1000 * 60 * 60 * 24 * 30 * 3) {
        return 'day';
    }
    if (dis <= 1000 * 60 * 60 * 24 * 30 * 24) {
        return 'month';
    }
    return 'year';
}

export function endDayOfMonth(date) {
    const curMonth = date.getMonth() + 1;
    let next = date.getMonth() + 1;
    while (curMonth === next) {
        const nextTime = date.getTime() + 1000 * 60 * 60 * 24;
        const nextDate = new Date(nextTime)
        const nextMonth = nextDate.getMonth() + 1; // 月份是从0开始的，所以需要+1
        if (nextMonth !== curMonth) {
            break
        }
        date = nextDate
        next = date.getMonth() + 1
    }
    const year = date.getFullYear();
    const month = date.getMonth() + 1; // 月份是从0开始的，所以需要+1
    const day = date.getDate();
    return year + '-' + month + '-' + day + ' 23:59:59';
}


export function getTimeInfo (date) {
    const timeLessTen = function (v) {
        if (v <= 9) {
            return '0' + v;
        }
        return v;
    }
    const year = date.getFullYear();
    const month = date.getMonth() + 1; // 月份是从0开始的，所以需要+1
    const day = date.getDate();
    const hours = date.getHours();
    const minutes = date.getMinutes();
    const seconds = date.getSeconds();
    const weekday = date.getDay();
    return {
        toYear: year,
        toMonth: year + '-' + timeLessTen(month),
        toDay: year + '-' + timeLessTen(month) + '-' + timeLessTen(day),
        toHour: year + '-' + timeLessTen(month) + '-' + timeLessTen(day) + ' ' + timeLessTen(hours),
        toMin: year + '-' + timeLessTen(month) + '-' + timeLessTen(day) + ' ' + timeLessTen(hours) + ':' + timeLessTen(minutes) + ':' + timeLessTen(seconds),
        year: year,
        month: timeLessTen(month),
        day: timeLessTen(day),
        hour: timeLessTen(hours),
        minute: timeLessTen(minutes),
        second: timeLessTen(seconds),
        weekOfDay: weekday
    };
}
